<?php
	check_login();
	$a = getAction();

	switch($a)
	{
		case 'index':
			$sql = " select *  from ".table('setting');
			$rs=$db->getRow($sql);
			$smarty->assign("formData",$rs);
			
			$smarty->display("setting_add.html");
			break;	
		
		case 'add':
			if($_POST) {
				$id=intval($_POST['id']);
				$formData = $_POST["formData"];
				
				if($id)
				{
					$db->update("setting", $formData, " and id = $id");
				}else
				{
					$db->insert("setting", $formData);
				}
		                
				errback("系统设置保存成功");
			} else {
				$sql="select *  from " . table('setting');
				$formData = $db->getRow($sql);
					
				$smarty->assign("formData", $formData);
				$smarty->display("setting_add.html");
			}
			break;
	}
    ?>